package homework3;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        try(
                FileOutputStream fos = new FileOutputStream("pw.txt");
                OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8");
                BufferedWriter bw = new BufferedWriter(osw);
                PrintWriter pw = new PrintWriter(bw,true);
        ){
            Scanner scanner = new Scanner(System.in);
            System.out.println("请开始输入内容");
            while(true) {
                String str = scanner.nextLine();
                if("exit".equals(str)) {
                    break;
                }
            pw.println(str);
            }
        }catch(Exception e) {
            e.printStackTrace();
        }
    }
}

